package io.github.wslxm.springbootplus2.client.sys.controller;

import io.github.wslxm.springbootplus2.client.sys.model.vo.USysDictGroupVO;
import io.github.wslxm.springbootplus2.client.sys.model.vo.USysDictVO;
import io.github.wslxm.springbootplus2.core.base.controller.BaseController;
import io.github.wslxm.springbootplus2.core.constant.BaseConstant;
import io.github.wslxm.springbootplus2.core.result.Result;
import io.github.wslxm.springbootplus2.manage.sys.service.SysDictService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;


/**
 * 字典表
 *
 * @author wangsong
 * @WX-QQ 1720696548
 * @date Sun Nov 24 11:23:12 CST 2019
 */
@RestController
@RequestMapping(BaseConstant.Uri.API_CLIENT + "/sys/dictionary")
@Tag(name = "yh--base--字典管理")
public class USysDictController extends BaseController<SysDictService> {


    @RequestMapping(value = "/findCodeGroup", method = RequestMethod.GET)
    @Operation(summary = "查询所有-code分组", description = "" +
            "<div>1、根据Code字段分组排列数据,分组下的数据仍然有层级关系</div>" +
            "\r\n <div>2、版本号(key=version)未发生变化后端不返回任何数据,前端请定义全局变量来缓存此字段</div>" +
            "\r\n <div>3、所有select选择框,状态字段都使用此接口的数据获取中文值</div>" +
            "\r\n <div>4、添加/更新/删除/修改排序后端都会更新版本号,重新拉取直接获取最新数据</div>" +
            "\r\n <div>5、包括禁用数据, disable 标识 </div>" +
            "\r\n 建议: 打开首页时调用此方法,刷新缓存数据, 刷新首页时在此刷新缓存"
    )
    public Result<Map<String, List<USysDictGroupVO>>> findCodeGroup() {
        return Result.successFind(baseService.findCodeGroup());
    }


    @GetMapping(value = "findByCode")
    @Operation(summary = "指定 code 查询字典列表", description = "通过字典code 查询当前字典下的所有可选数据 ")
    public Result<List<USysDictVO>> findByCode(@RequestParam(required = true) String code) {
        return Result.success(baseService.findByCode(code));
    }


    @GetMapping(value = "findByCodeNext")
    @Operation(summary = "指定 code + 字典值 code 查询指定字典", description = "")
    public Result<USysDictVO> findByCodeNext(@RequestParam(required = true) String code, @RequestParam(required = true) String nextCode) {
        return Result.success(baseService.findByCodeNext(code, nextCode));
    }
}

